using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.ExpFormat {
    /// <summary>
    /// extracted info from syntax tree(<see cref="LRNode"/>).
    /// </summary>
    public partial class Exp : IVnNode {
        // [-1]=Exp' : Exp ;
        // dumped by ExternalExtractor
        internal readonly VnExp @final;

        internal Exp(VnExp final) {
            this.@final = final;
        }

        public TokenRange Scope => this.final.Scope;


        public void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
            {
                //context.PrintComment(context.tokens[0], this._translationUnit, writer);
                var start = 0;
                var end = this.final.Scope.start - 1;
                var switches1 = new BlankConfig(inlineBlank: 1, forceNewline: false);
                context.PrintCommentsBetween(start, end, switches1, writer);
            }
            context.PrintBlanksAnd(this.final, preConfig, writer);
            {
                //context.PrintComment(this._translationUnit, context.tokens[context.tokens.Count - 1], writer);
                var start = this.final.Scope.end + 1;
                var end = context.tokens.Count - 1;
                var switches1 = new BlankConfig(inlineBlank: 1, forceNewline: false);
                context.PrintCommentsBetween(start, end, switches1, writer);
            }
        }

        public void PrintFlatTree(TextWriter writer, IReadOnlyList<string> stArray) {
            IInherit.Print(final, writer, stArray);
        }

        IInherit? IInherit.Parent { get; set; }
        IEnumerable<IInherit> IInherit.ReversedChildren() {
            yield return this.final;
        }
        public void PrintSelf(TextWriter writer, IReadOnlyList<string>? stArray) {
            this.final.PrintSelf(writer, stArray);
        }
    }
}
